package com.ego.goodsweb.controller;

import com.ego.goodsweb.service.GoodsWebService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsController {

    @Resource
    private GoodsWebService goodsWebService;

    /**
     * 跳转到商品详情页
     * @param model
     * @param id
     * @return
     */
    @GetMapping("{id}.html")
    public String toItemPage(Model model, @PathVariable("id") Long id){

        //1.查询出模型数据
        Map<String,Object> modelMap = goodsWebService.loadModel(id);
        //2.将数据发送给视图
        model.addAllAttributes(modelMap);
        //3.并行生成静态页面
//        goodsWebService.createStaticHtml(id,modelMap);
        //4.渲染并响应
        return "item";
    }
}
